//
//  Tool.swift
//  WeiBoAPP
//
//  Created by ios001 on 2022/11/28.
//  Copyright © 2022 zxf. All rights reserved.
//

import UIKit

class Tool: NSObject {
    
    // 获取当前控制器

    ///获取当前控制器
    class func currentController() ->UIViewController{

        var vc = UIApplication.shared.keyWindow?.rootViewController

        if (vc?.isKind(of: UITabBarController.self))! {
            vc = (vc as! UITabBarController).selectedViewController
            if ((vc?.isKind(of: UINavigationController.self)) != nil) {
                vc = (vc as! UINavigationController).visibleViewController
            }
        }else if (vc?.isKind(of: UINavigationController.self))!{
            vc = (vc as! UINavigationController).visibleViewController
        }else if ((vc?.presentedViewController) != nil){
            vc =  vc?.presentedViewController
        }

        return vc!

    }
    
    
    class func currentController2(vc2:UIViewController?) ->UIViewController{

        var vc = vc2
        if (vc?.isKind(of: UITabBarController.self))! {
            vc = (vc as! UITabBarController).selectedViewController
        }else if (vc?.isKind(of: UINavigationController.self))!{
            vc = (vc as! UINavigationController).visibleViewController
        }else if ((vc?.presentedViewController) != nil){
            vc =  vc?.presentedViewController
        }

        return vc!

    }
    //    //实际项目中调用
    //    if let myVC = getCurrentVC1() as? myVC {
    //    .......
    //    }
    
    
    
    
}

